$(document).ready(function() {
	
	$(".sx_filterself dd a").click(function() {
		var url = window.location.href;
		var pddq = $(this).attr('name') + "=" + $(this).attr('rel');
		var mark = false;
		if(url.split('?').length < 2) {
			url = url + ('?' + pddq);
			window.location.href = url;
		} else {
			var urlarr = window.location.href.split("?");
			var jieduanurl = urlarr[1];
			var jdurlarr = jieduanurl.split('&');
			for(var k in jdurlarr) {
				if(jdurlarr[k] == pddq) {
					var mark = true;
				}
			}
			if(mark) {
				window.location.href = url;
			} else {
				url = url + ('&' + pddq);
				window.location.href = url;
			}
		}
	})
	$('.sx_filter').sx({
		nuv: ".sx_result", //筛选结果
		zi: "sx_child", //所有筛选范围内的子类
		qingchu: '.clearCont', //清除全部
		over: 'on' //选中状态样式名称
	});
	$(".retract").toggle(function() {
		$(".show_hide").css("display", "none")
	}, function() {
		$(".show_hide").css("display", "block");
	});
	$(".firstP").click(function() {
		location.href = "joblist_xz_zwzd.html";
	});
	$(".sz_tlyc2 p").bind('click', function() {
		$(this).siblings().css({
			'background-color': 'transparent',
			'color': '#e41f2b'
		});
		$(this).siblings().find('span').css({
			'color': '#e41f2b'
		});
		$(this).css({
			'background-color': '#e41f2b',
			'color': 'white'
		});
		$(this).find('span').css({
			'color': 'white'
		});
	})

	//浮层
	$(".showtc").click(function() {
		$("body").css({'overflow-y':'hidden','padding':'0 17px 0 0'})
		$(".suspend").css('margin-left',"577.5px");
		$(".tanceng,.choseCity").show();
	})
	var allChoseCity = {};
	var cc = [{
		name: "A",
		order: "1",
		children: [{
			allcountry: "全国",
			name: "A1",
			id: "A1",
			order: "1",
			children: [{
				name: "A11",
				order: "1",
				children: [{}],
				id: "a11"
			}, {
				name: "A12",
				order: "2",
				children: [{}],
				id: "a12"
			}]
		}, {
			allcountry: "全国",
			name: "A2",
			id: "A2",
			order: "2",
			children: [{
				name: "A21",
				order: "1",
				children: [{}],
				id: "a21"
			}, {
				name: "A22",
				order: "2",
				children: [{}],
				id: "a22"
			}]
		}]
	}, {
		name: "B",
		order: "2",
		children: [{
			allcountry: "全国",
			name: "B1",
			id: "B1",
			order: "1",
			children: [{
				name: "B11",
				order: "1",
				children: [{}],
				id: "b11"
			}, {
				name: "B12",
				order: "2",
				children: [{}],
				id: "b12"
			}]
		}, {
			allcountry: "全国",
			name: "B2",
			id: "B2",
			order: "2",
			children: [{
				name: "B21",
				order: "1",
				children: [{}],
				id: "b21"
			}, {
				name: "B22",
				order: "2",
				children: [{}],
				id: "b22"
			}]
		}]
	}, {
		name: "C",
		order: "3",
		children: [{
			allcountry: "全国",
			name: "C1",
			id: "C1",
			order: "1",
			children: [{}]
		}, {
			name: "C2",
			id: "C2",
			order: "2",
			children: [{}]
		}]
	}, {
		name: "D",
		order: "4",
		children: [{
			allcountry: "全国",
			name: "D1",
			id: "D1",
			order: "1",
			children: [{}]
		}, {
			name: "D2",
			id: "D2",
			order: "2",
			children: [{}]
		}]
	}, {
		name: "E",
		order: "5",
		children: [{
			allcountry: "全国",
			name: "E1",
			id: "E1",
			order: "1",
			children: [{}]
		}, {
			name: "E2",
			id: "E2",
			order: "2",
			children: [{}]
		}]
	}, {
		name: "F",
		order: "6",
		children: [{
			allcountry: "全国",
			name: "F1",
			id: "F1",
			order: "1",
			children: [{}]
		}, {
			name: "F2",
			id: "F2",
			order: "2",
			children: [{}]
		}]
	}, {
		name: "G",
		order: "7",
		children: [{
			allcountry: "全国",
			name: "G1",
			id: "G1",
			order: "1",
			children: [{}]
		}, {
			name: "G2",
			id: "G2",
			order: "2",
			children: [{}]
		}]
	}, {
		name: "H",
		order: "8",
		children: [{
			allcountry: "全国",
			name: "H1",
			id: "H1",
			order: "1",
			children: [{}]
		}, {
			name: "H2",
			id: "H2",
			order: "2",
			children: [{}]
		}]
	}, {
		name: "I",
		order: "9",
		children: [{
			allcountry: "全国",
			name: "I1",
			id: "I1",
			order: "1",
			children: [{}]
		}, {
			name: "I2",
			id: "I2",
			order: "2",
			children: [{}]
		}]
	}, {
		name: "J",
		order: "10",
		children: [{
			allcountry: "全国",
			name: "J1",
			id: "J1",
			order: "1",
			children: [{}]
		}, {
			name: "J2",
			id: "J2",
			order: "2",
			children: [{}]
		}]
	}, {
		name: "K",
		order: "11",
		children: [{
			allcountry: "全国",
			name: "K1",
			id: "K1",
			order: "1",
			children: [{}]
		}, {
			name: "K2",
			id: "K2",
			order: "2",
			children: [{}]
		}]
	}, {
		name: "L",
		order: "12",
		children: [{
			allcountry: "全国",
			name: "L1",
			id: "L1",
			order: "1",
			children: [{}]
		}, {
			name: "L2",
			id: "L2",
			order: "2",
			children: [{}]
		}]
	}, {
		name: "M",
		order: "13",
		children: [{
			allcountry: "全国",
			name: "M1",
			id: "M1",
			order: "1",
			children: [{}]
		}, {
			name: "M2",
			id: "M2",
			order: "2",
			children: [{}]
		}]
	}, {
		name: "N",
		order: "14",
		children: [{
			allcountry: "全国",
			name: "N1",
			id: "N1",
			order: "1",
			children: [{}]
		}, {
			name: "N2",
			id: "N2",
			order: "2",
			children: [{}]
		}]
	}, {
		name: "O",
		order: "15",
		children: [{
			allcountry: "全国",
			name: "O1",
			id: "O1",
			order: "1",
			children: [{}]
		}, {
			name: "O2",
			id: "O2",
			order: "2",
			children: [{}]
		}]
	}, {
		name: "P",
		order: "16",
		children: [{
			allcountry: "全国",
			name: "P1",
			id: "P1",
			order: "1",
			children: [{}]
		}, {
			name: "P2",
			id: "P2",
			order: "2",
			children: [{}]
		}]
	}, {
		name: "Q",
		order: "17",
		children: [{
			allcountry: "全国",
			name: "Q1",
			id: "Q1",
			order: "1",
			children: [{}]
		}, {
			name: "Q2",
			id: "Q2",
			order: "2",
			children: [{}]
		}]
	}, {
		name: "R",
		order: "18",
		children: [{
			allcountry: "全国",
			name: "R1",
			id: "R1",
			order: "1",
			children: [{}]
		}, {
			name: "R2",
			id: "R2",
			order: "2",
			children: [{}]
		}]
	}, {
		name: "S",
		order: "19",
		children: [{
			allcountry: "全国",
			name: "S1",
			id: "S1",
			order: "1",
			children: [{}]
		}, {
			name: "S2",
			id: "S2",
			order: "2",
			children: [{}]
		}]
	}, {
		name: "T",
		order: "20",
		children: [{
			allcountry: "全国",
			name: "T1",
			id: "T1",
			order: "1",
			children: [{}]
		}, {
			name: "T2",
			id: "T2",
			order: "2",
			children: [{}]
		}]
	}, {
		name: "U",
		order: "21",
		children: [{
			allcountry: "全国",
			name: "U1",
			id: "U1",
			order: "1",
			children: [{}]
		}, {
			name: "U2",
			id: "U2",
			order: "2",
			children: [{}]
		}]
	}, {
		name: "V",
		order: "22",
		children: [{
			allcountry: "全国",
			name: "V1",
			id: "V1",
			order: "1",
			children: [{}]
		}, {
			name: "V2",
			id: "V2",
			order: "2",
			children: [{}]
		}]
	}, {
		name: "W",
		order: "23",
		children: [{
			allcountry: "全国",
			name: "W1",
			id: "W1",
			order: "1",
			children: [{}]
		}, {
			name: "W2",
			id: "W2",
			order: "2",
			children: [{}]
		}]
	}, {
		name: "X",
		order: "24",
		children: [{
			allcountry: "全国",
			name: "X1",
			id: "X1",
			order: "1",
			children: [{}]
		}, {
			name: "X2",
			id: "X2",
			order: "2",
			children: [{}]
		}]
	}, {
		name: "Y",
		order: "25",
		children: [{
			allcountry: "全国",
			name: "Y1",
			id: "Y1",
			order: "1",
			children: [{}]
		}, {
			name: "Y2",
			id: "Y2",
			order: "2",
			children: [{}]
		}]
	}, {
		name: "Z",
		order: "26",
		children: [{
			allcountry: "全国",
			name: "Z1",
			id: "Z1",
			order: "1",
			children: [{}]
		}, {
			name: "Z2",
			id: "Z2",
			order: "2",
			children: [{}]
		}]
	}];
	$(".world").click(function() {
		if(!allChoseCity["world"]) {
			$("#aworld").show();
			allChoseCity["world"] = true;
		}
	})
	canSlide=true;
	$(".country").live('click', function() {
		var c = $(this).attr("class");
		if(c.indexOf("nonactive") > 0 && canSlide) {
			if($(this).siblings().length==0){
				canSlide=true;
			}
			else{
				canSlide=false;
			}
			$('.city').slideUp();
			$('.allcity').slideUp(function(){
				canSlide=true;
			});
			$(this).siblings().slideDown();
			$(".country").removeClass("active").addClass("nonactive");
			$(this).removeClass("nonactive").addClass("active");
		} else if(c.indexOf("active") > 0 && canSlide) {
			if($(this).siblings().length == 0) {
				canSlide = true;
			} else {
				canSlide = false;
			}
			//$(this).siblings().stop();
			$(this).siblings().slideUp(function(){
				canSlide=true;
			});
			$(this).removeClass("active").addClass("nonactive");
		}
	})

	$(".city label").live("click", function() {
		$(this).addClass("on");
		var className = $(this).attr("class");
		var id = $(this).attr("id");
		var city = $(this).parents(".city").text();
		if(className.indexOf("selected") >= 0 && allChoseCity[id] && className.indexOf("can") < 0) {
			allChoseCity[id] = false;
			$("#a" + id).remove();
			$(this).removeClass("selected");
		} else if(className.indexOf("selected") < 0 && !allChoseCity[id] && className.indexOf("can") < 0) {
			$(this).addClass("selected");
			allChoseCity[id] = true;
			var html = "<a id='a" + id + "'name='city' rel='"+id+"'><span style='height: 24px;line-height: 24px;display: inline-block;vertical-align: top;'>" + city + "</span><span class='closecity'></span></a>";
			$("#allchose").append(html);
		}
	})

	$(".allcity label").live("click", function() {
		$(this).addClass('on');
		var className = $(this).attr("class");
		var country = $(this).parents().siblings('.country').text();
		var id = $(this).attr("id");
		if(className.indexOf("selected") < 0 && !allChoseCity[id]) {
			$(this).addClass("selected");
			allChoseCity[id] = true;
			var html = "<a id='a" + id + "'name='city' rel='"+id+"'><span style='height: 24px;line-height: 24px;display: inline-block;vertical-align: top;'>" + country + "</span><span class='closecity'></span></a>";
			$("#allchose").append(html);
			$(this).parents(".allcity").siblings('.city').find("label").removeClass("selected").addClass("cannotsele");
			var labels = $(this).parents(".allcity").siblings('.city').find("label");
			for(var i = 0; i < labels.length; i++) {
				var ids = $(labels[i]).attr("id");
				allChoseCity[ids] = false;
				$("#a" + ids).remove();
			}
		} else {
			allChoseCity[id] = false;
			$("#a" + id).remove();
			$(this).removeClass("selected");
			$(this).parents(".allcity").siblings('.city').find("label").removeClass("cannotsele");
		}
	})

	$("#allchose a").live("click", function() {
		var city = $(this).text();
		var id = $(this).attr("id").substring(1);
		if(id.indexOf("world") >= 0) {
			$(this).hide();
		} else {
			$(this).remove();
			$("#" + id).removeClass();
			$("#" + id).parents(".allcity").siblings(".city").find("label").removeClass();
		}
		allChoseCity[id] = false;
	})

	$(".shulie a").live("click", function() {
		var tag = $(this).text();
		var top = $(".midcontent ul[name='" + tag + "']:first").position().top + $(".midcontent").scrollTop();
		$(".midcontent").animate({
			scrollTop: top
		}, 500);
	})

	$(".subbtn").click(function() {
		var citys = $("#allchose a");
		var html = ""
		var result = $(".sx_result a");
		for(var i = 0; i < citys.length; i++) {
			var name = $(citys[i]).text();
			var repeat = false;
			for(var j = 0; j < result.length; j++) {
				if(name == $(result[j]).text()) {
					repeat = true;
					break;
				}
			}
			if($(citys[i]).is(":visible") && !repeat) {
				html += "<a rel='" +$(citys[i]).attr("id")+ "'name='city' href='javascript:;'>" + name + "</a>"
			}
		}
		//        $("#workLocation").empty();
		$(".clearCont").before(html);
		if(!$(".clearCont").is(":visible")) {
			$(".clearCont").show()
		}

		var url = window.location.href;
		var pddq = ""; // "name=" + $(this).attr('id').substring(1);
		for(var i = 0; i < citys.length; i++) {
			if(i != citys.length - 1 && $(citys[i]).is(":visible")) {
				pddq += $(citys[i]).attr("name") + "=" + ($(citys[i]).attr("rel")) + "&";
			} else if(i == citys.length - 1) {
				pddq += $(citys[i]).attr("name") + "=" + ($(citys[i]).attr("rel"));
			}

		}
		var mark = false;
		if(url.split('?').length < 2) {
			url = url + ('?' + pddq);
			window.location.href = url;
		} else {
			var urlarr = window.location.href.split("?");
			var jieduanurl = urlarr[1];
			var jdurlarr = jieduanurl.split('&');
			for(var k in jdurlarr) {
				if(jdurlarr[k] == pddq) {
					var mark = true;
				}
			}
			if(mark) {
				window.location.href = url;
			} else {
				url = url + ('&' + pddq);
				window.location.href = url;
			}
		}
	})

	//	关闭弹层
	$(".close").click(function() {
//		$("body").css('overflow','scroll');
		$("body").css({'overflow-y':'scroll','padding':'0 0px 0 0'});
		$(".suspend").css('margin-left',"586px")
		$(".tanceng,.choseCity").hide();
	})

	//	关于国家以及城市
	var width = document.documentElement.clientWidth == 0 ? document.body.clientWidth : document.documentElement.clientWidth;
	var height = document.documentElement.clientHeight == 0 ? document.body.clientHeight : document.documentElement.clientHeight;
	var left = (width - $(".choseCity").width()) / 2
	$(".choseCity").css("left", left + "px");

	$(window).resize(function() {
		var width = document.documentElement.clientWidth == 0 ? document.body.clientWidth : document.documentElement.clientWidth;
		var left = (width - $(".choseCity").width()) / 2
		$(".choseCity").css("left", left + "px");
	})

	$(".midcontent").empty();
	$(".shulie").empty();
	$(".shulie").hide();
	$("#allchose").empty();
	$("#allchose").append("<a id='aworld' style='display: none;' name='city' rel='1'><span style='height: 24px;line-height: 24px;display: inline-block;vertical-align: top;'>" + $(".world").text() + "</span><span class='closecity'></span></a>");
	var html = "";
	for(var i = 0; i < cc.length; i++) {
		html += "<a>" + cc[i].name + "</a>";
		var country = cc[i].children;
		for(var j = 0; j < country.length; j++) {
			if(typeof(country[j].allcountry) == "undefined") {
				html1 = "<ul name='" + cc[i].name + "'class='clearfix'><li class='country nonactive sx_child' rel='" + country[j].id + "' name='city'>" + (typeof(country[j].name) == "undefined" ? " " : country[j].name) + "</li>"
			} else {
				html1 = "<ul name='" + cc[i].name + "'class='clearfix'><li class='country nonactive sx_child' rel='" + country[j].id + "' name='city'>" + (typeof(country[j].name) == "undefined" ? " " : country[j].name) + "</li><li class='allcity'><label id='" + country[j].id + "'></label>" + (typeof(country[j].allcountry) == "undefined" ? " " : country[j].allcountry) + "</li>"
			}
			var city = country[j].children;
			for(var ii = 0; ii < city.length; ii++) {
				if(JSON.stringify(city) == "[{}]") {
					html1 += "</ul>";
					$(".midcontent").append(html1);
				} else if(ii != city.length - 1) {
					html1 += "<li rel='" + city[ii].id + "' class='sx_child city ' name='city'><label id='" + city[ii].id + "'></label>" + (typeof(city[ii].name) == "undefined" ? " " : city[ii].name) + "</li>"
				} else {
					html1 += "<li rel='" + city[ii].id + "' class='sx_child city' name='city'><label id='" + city[ii].id + "'></label>" + (typeof(city[ii].name) == "undefined" ? " " : city[ii].name) + "</li></ul>"
					$(".midcontent").append(html1);
				}
			}
		}
	}
	$(".shulie").append(html);
	$(".letterNav").css("height", cc.length * 16 + "px");
	$(".shulie").show();

	//搜索事件
	$(".sz .filtering dl.keyword dd input").keydown(function() {
		$(".sz .filtering dl.keyword dd .search").css('background', 'url("img/search_icon2.png") no-repeat right top');
	})

	$(".sz .filtering dl.keyword dd input").blur(function() {
		if($(".sz .filtering dl.keyword dd input").val() == "") {
			$(".sz .filtering dl.keyword dd .search").css('background', 'url("img/search_icon3.png") no-repeat right top')
		}
	})

	//	点击更多
//	$(".filtering dt.more").toggle(function() {
//		$(this).find("span").attr("class", "triangle-down")
//		$(this).parent().find("p.moreCont").show();
//	}, function() {
//		$(this).find("span").attr("class", "triangle-right");
//		$(this).parent().find("p.moreCont").hide();
//	});


	$(".filtering dt.more").toggle(function() {
		$(this).find("span").attr("class", "triangle-down");	
//		$(this).parents(".sx_filter").find(".citys").css({'overflow':'','height':""});
		$(this).parents(".sx_filter").find(".addsss_childs").css({"overflow":"auto","height":"auto"});
//		$(this).parent().find("p.moreCont").show();
	}, function() {
		$(this).find("span").attr("class", "triangle-right");
//		$(this).parent().find("p.moreCont").hide();
		$(this).parents(".sx_filter").find(".addsss_childs").css({"overflow":"hidden","height":"22px"});

	});
})